import { createApp } from 'vue'
import App from './App.vue'
import pinia from '@/stores/pinia.ts'
import i18n from '@/utils/locale.ts'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import * as KitegoIcons from '@/assets/icons/index.ts'
import directives from '@/directives'

import '@/assets/style/element.scss'
import '@/assets/style/style.scss'
import '@/assets/style/tailwind.css'

const app = createApp(App)

app.use(directives)
app.use(pinia)
app.use(i18n(pinia))
app.use(router)

// 统一注册el-icon图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(`ElIcon${key}`, component)
}
// 统一注册kitego-icon图标
for (const [key, component] of Object.entries(KitegoIcons)) {
    app.component(`KitegoIcon${key}`, component)
}

// 捕捉全局错误
app.config.errorHandler = (err, instance, info) => {
    console.error('捕获到全局错误：', err)
    console.error('出错的组件实例：', instance)
    console.error('错误信息：', info)
}

app.mount('#app')
